import 'package:expandable_text/expandable_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:largefriends/res/lf_double_ext.dart';
import 'package:largefriends/res/lf_string_ext.dart';

import '../../../config/lf_im_type.dart';
import '../../../entity/entities/chat_new_message_entity.dart';
import '../../../res/lf_color.dart';
import '../../../res/lf_fonts.dart';
import '../../../res/lf_text_style.dart';
import '../../../res/lf_widget_ext.dart';
import '../../../res/strings/lf_strings.dart';
import '../../../service/lf_auth_service.dart';

class LfMessageCompanionWidget extends StatelessWidget {
  final ChatNewMessageEntity data;
  final String userName;
  const LfMessageCompanionWidget(
      {super.key, required this.data, required this.userName});

  @override
  Widget build(BuildContext context) {
    if (data.companyInfo == null) {
      return empty;
    }
    LfAuthService authService = Get.find();
    var isSender =
        data.sender?.profile?.userId == authService.currentAccount!.userId;
    var itemTitle = "";
    if (IMMessageType.likeCompanion.value.toString() == data.messageType) {
      itemTitle = strIAmInterestred.tr;
    } else if (IMMessageType.rehostCompanion.value.toString() ==
        data.messageType) {
      itemTitle = strIAskToRehost.tr;
    } else if (IMMessageType.approvedCompanion.value.toString() ==
        data.messageType) {
      ///暂时没有这个消息类型,所以不用怎么处理
      itemTitle = strIAppliedToAttend.tr;
    } else {
      itemTitle = strIAppliedToAttend.tr;
    }

    var textColor = isSender ? colorFEFEFE : colorFEFEFE;
    return Row(
      mainAxisAlignment:
          isSender ? MainAxisAlignment.end : MainAxisAlignment.start,
      children: [
        10.w.sbw,
        Container(
          width: ScreenUtil().screenWidth - 70.w,
          decoration: BoxDecoration(
            color: isSender ? color514F62 : color8F8F8F,
            borderRadius: BorderRadius.only(
                topRight: isSender ? Radius.zero : Radius.circular(10.r),
                topLeft: isSender ? Radius.circular(10.r) : Radius.zero,
                bottomRight: Radius.circular(10.r),
                bottomLeft: Radius.circular(10.r)),
          ),
          padding: EdgeInsets.symmetric(horizontal: 10.r, vertical: 8.h),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              Text(
                itemTitle,
                style: lfTextStyle(
                    sp: 15.sp, fontFamily: fontMedium, color: textColor),
              ),
              Container(
                color: isSender ? colorFEFEFE.withAlpha(100) : colorFEFEFE,
                height: 2.r,
                margin: EdgeInsets.symmetric(vertical: 5.h),
              ),
              ExpandableText(
                data.companyInfo?.title?.replaceBreak ?? "",
                expandText: '${strMore.tr}>>',
                collapseText: '<<${strLess.tr}',
                expandOnTextTap: true,
                animation: true,
                collapseOnTextTap: false,
                linkColor: colorFEFEFE,
                linkEllipsis: false,
                maxLines: 6,
                // position:
                style: lfTextStyle(
                    sp: 15.sp, fontFamily: fontRegular, color: textColor),
              ),
              8.h.sbh,
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '${strLocation.tr}:',
                    style: lfTextStyle(
                        sp: 13.sp, fontFamily: fontMedium, color: textColor),
                  ),
                  8.w.sbw,
                  Expanded(
                      child: Text(
                    data.companyInfo?.destination?.toAddress() ?? "",
                    style: lfTextStyle(
                        sp: 13.sp,
                        fontFamily: fontRegular,
                        color: textColor.withAlpha(200)),
                  ))
                ],
              ),
              8.h.sbh,
              Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Text(
                    '${strTime.tr}:',
                    style: lfTextStyle(
                        sp: 13.sp, fontFamily: fontMedium, color: textColor),
                  ),
                  8.w.sbw,
                  Expanded(
                      child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        data.companyInfo?.getStartDate() ?? "",
                        style: lfTextStyle(
                            sp: 13.sp,
                            fontFamily: fontRegular,
                            color: textColor.withAlpha(200)),
                      ),
                      Text(
                        data.companyInfo?.getEndDate() ?? "",
                        style: lfTextStyle(
                            sp: 13.sp,
                            fontFamily: fontRegular,
                            color: textColor.withAlpha(200)),
                      )
                    ],
                  ))
                ],
              ),
            ],
          ),
        ),
        10.w.sbw,
      ],
    );
  }
}
